import base64
import os

import httpx
from langchain_core.messages import HumanMessage
from langchain_openai import ChatOpenAI

image_url = "https://pic1.zhimg.com/v2-19d657e1f93c77e381205bf64d37ed58_r.jpg"
image_data = base64.b64encode(httpx.get(image_url).content).decode("utf-8")
model = ChatOpenAI(model_name="gpt-4o")

message = HumanMessage(content=[
    {"type": "text", "text": "用中文描述这张图片的天气"},
    # 如果图片地址是大模型访问不到的，因为网络问题，那么需要使用base64编码
    {"type":"image_url" , "image_url": {"url": image_url}}
])

response = model.invoke([message])
print(response.content)